/**
 * 
 */
package vn.edu.fpt.xml.hrm.controller.approval;

import java.io.IOException;
import java.sql.SQLException;
import javax.naming.NamingException;
import javax.xml.stream.XMLStreamException;

import vn.edu.fpt.xml.hrm.common.AppConstant;
import vn.edu.fpt.xml.hrm.common.FormatUtil;
import vn.edu.fpt.xml.hrm.controller.AbstractController;
import vn.edu.fpt.xml.hrm.model.ActivityBean;
import vn.edu.fpt.xml.hrm.pojo.Timesheet;

/**
 * @author Yoshimi
 * 
 */
public class ApproveActivitiesController extends AbstractController {

	/**
	 * 
	 */
	private static final long serialVersionUID = 4132692454331417636L;

	/*
	 * (non-Javadoc)
	 * 
	 * @see vn.edu.fpt.xml.hrm.controller.AbstractController#execute()
	 */
	@Override
	protected String execute() throws SQLException, ClassNotFoundException, NamingException, IOException, XMLStreamException {
		String[] idsS = null;
		int[] ids = null;
		String status = null;
		ActivityBean activityBean = null;

		idsS = getRequest().getParameterValues("selActs");
		if (idsS != null && idsS.length > 0) {
			status = "approved";
			ids = FormatUtil.stringToInt(idsS);
			activityBean = new ActivityBean();
			if (activityBean.updateStatus(ids, status) > 0) {
				Timesheet.createXMLTimeSheet(getServletContext().getRealPath("/") + "WEB-INF/timesheet.xml");
			}
		}
		return AppConstant.URL_LIST_APPROVE;
	}

}
